package com.ruoyi.web.controller.used;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.used.domain.UsedReply;
import com.ruoyi.used.service.IUsedReplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回复评价Controller
 * 
 * @author ruoyi
 * @date 2020-07-13
 */
@Controller
@RequestMapping("/used/reply")
public class UsedReplyController extends BaseController
{
    private String prefix = "used/reply";

    @Autowired
    private IUsedReplyService usedReplyService;

    @RequiresPermissions("used:reply:view")
    @GetMapping()
    public String reply()
    {
        return prefix + "/reply";
    }

    /**
     * 查询回复评价列表
     */
    @RequiresPermissions("used:reply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UsedReply usedReply)
    {
        startPage();
        List<UsedReply> list = usedReplyService.selectUsedReplyList(usedReply);
        return getDataTable(list);
    }

    /**
     * 导出回复评价列表
     */
    @RequiresPermissions("used:reply:export")
    @Log(title = "回复评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UsedReply usedReply)
    {
        List<UsedReply> list = usedReplyService.selectUsedReplyList(usedReply);
        ExcelUtil<UsedReply> util = new ExcelUtil<UsedReply>(UsedReply.class);
        return util.exportExcel(list, "reply");
    }

    /**
     * 新增回复评价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存回复评价
     */
    @RequiresPermissions("used:reply:add")
    @Log(title = "回复评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UsedReply usedReply)
    {
        return toAjax(usedReplyService.insertUsedReply(usedReply));
    }

    /**
     * 修改回复评价
     */
    @GetMapping("/edit/{reId}")
    public String edit(@PathVariable("reId") Long reId, ModelMap mmap)
    {
        UsedReply usedReply = usedReplyService.selectUsedReplyById(reId);
        mmap.put("usedReply", usedReply);
        return prefix + "/edit";
    }

    /**
     * 修改保存回复评价
     */
    @RequiresPermissions("used:reply:edit")
    @Log(title = "回复评价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UsedReply usedReply)
    {
        return toAjax(usedReplyService.updateUsedReply(usedReply));
    }

    /**
     * 删除回复评价
     */
    @RequiresPermissions("used:reply:remove")
    @Log(title = "回复评价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(usedReplyService.deleteUsedReplyByIds(ids));
    }
}
